﻿using Glue.Internals;
using Xunit;

namespace GlueTests
{
    namespace NullableTypeMapperTest
    {
        public class When_converting_from_nullable_Type
        {
            private readonly NullableTypeMapper mapper;

            public When_converting_from_nullable_Type()
            {
                mapper = new NullableTypeMapper(typeof(int?),typeof(int));
            } 

            [Fact]
            public void Should_convert_normal_values_as_normal()
            {
                int? nullableInt = 13;
                int normalInt = 0;
                Assert.Equal(13,(int)mapper.Map(nullableInt,normalInt));
            }

            [Fact]
            public void Should_convert_null_to_default()
            {
                int? nullableInt = null;
                int normalInt = 0;
                normalInt = (int)mapper.Map(nullableInt, normalInt);
                Assert.Equal(0, normalInt);
            }
        }
    }
}
